<?php
include_once 'header_php.php';
$title='Recherche';
include_once 'header_html.php';
$post_pers=$_POST['personnes'];
$post_asso=$_POST['asso'];
$post_debut=$_POST['debut'];
$post_fin=$_POST['fin'];


?>
<div class="wrapper">		
		<div class="container-fluid">
                    <br/><br/>
                    <h3 class ="span8 offset2" >
                        <?php
                        
                        echo 'Vous avez demandé la liste des '.$post_pers.'s de ';
                        foreach($post_asso as $var){
                            echo ' '.$var.' ';
                        }
                        echo 'entre le semestre '.$post_debut.' et le semestre '.$post_fin.' : ';
                        
                        ?>
                    </h3>
                    <br/><br/>
                    <br/><br/>
                    <br/><br/>
                    <?php
                    $sql="SELECT semestre,association,personne,role ".
                    "FROM membreasso MA, apourrole AP WHERE ("; 
                    foreach($post_asso as $var){
                        $sql=$sql." MA.association='".$var."' OR ";
                    }
                    $sql=$sql."1=0) AND AP.membreasso=MA.id";
                    if($post_pers=="bureaux complet"){
                        $sql=$sql." AND (AP.role='Président' OR AP.role='Trésorier' OR AP.role='Secrétaire') ";
                    }
                    else if($post_pers!="membres"){
                        $sql=$sql." AND AP.role='".$post_pers."'";
                    }
                    
                    $sql=$sql." AND cast(substring(MA.semestre,2,2) AS integer)>=cast(substring('".$post_debut."',2,2) AS integer)";
                    $sql=$sql." AND cast(substring(MA.semestre,2,2) AS integer)<=cast(substring('".$post_fin."',2,2) AS integer)";
                    $sql=$sql." ORDER BY MA.association,MA.semestre;";
                    
                    //echo $sql;
                    
                    
                    
                    echo'<table class="table table-striped span8 offset2">';
                    echo'<thead>';
                    echo'<tr>';
                    echo '<th>Semestre</th><th>Association</th><th>Login</th><th>Rôle</th>';
                    echo'</tr>';
                    echo'</thead>';
                    echo '<tbody>';
                    
                    $querySql= new DbQuery($db,$sql);
                    $querySql->SendQuery();
                    while($result=$querySql->GetResult()){
                        echo '<tr>';
                        echo '<td>'.$result['semestre'].'</td>';
                        echo '<td>'.$result['association'].'</td>';
                        echo '<td>'.$result['personne'].'</td>';
                        echo '<td>'.$result['role'].'</td>';
                        echo '</tr>';
                        }
                    echo  '</tbody>';
                    echo '</table>';
                    ?>
                </div>
    
</div><!-- /container -->


<?php 
    include_once 'footer.php'; 
?>
